<?php

namespace App\Transformers\Admin;

use League\Fractal\TransformerAbstract;

class UserTransformer extends TransformerAbstract
{
    public $availableIncludes = ['roles', 'section'];

    public function transform($user)
    {
        return [
            'id' => $user->id,
            'name' => $user->name,
            'username' => $user->username,
            'email' => $user->email,
            'phone' => $user->phone ?? '',
            'id_card' => $user->id_card,
            'status' => $user->status,
            'avatar' => $user->avatar,
            'avatar_url' => $user->avatar ? ossUrl($user->avatar) : null
        ];
    }

    public function includeRoles($user)
    {
        return $this->collection($user->roles, new RoleTransformer());
    }

    public function includeSection($user)
    {
        return $this->collection($user->section, new SectionTransformer());
    }
}
